package com;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ThreadSocketServer  implements Runnable{
	MySocketServer mySocketServer;
	ServerSocket serverSocket;

	public ThreadSocketServer(MySocketServer mySocketServer) {
		this.mySocketServer= mySocketServer;
		serverSocket = this.mySocketServer.getServerSocket();
	}


	
	//处理socket
	public void service(){
		InputStream socketInputStream = null;
		OutputStream socketOutputStream = null;
		Socket socket = null;
		try{
			BufferedReader bfin = null;
			System.out.println("The server is waiting your input...");
			socket = serverSocket.accept();
			socketInputStream = socket.getInputStream();
			byte[] b = new byte[512];
			int i = 0;
			i = socketInputStream.read(b);
			System.out.println("输入了:" + new String(b));
		}catch(Exception e){
			
		}finally{
			try{
				if(socketOutputStream!=null){
					socketOutputStream.close();
				}
				if(socketInputStream!=null){
					socketInputStream.close();
				}
				socket.close();
			}catch(Exception e){
				
			}
		}
	}
	@Override
	public void run() {
		this.service();
		mySocketServer.recycle(this);
	}
}
